package router

import (
	"github.com/gin-gonic/gin"
	swaggerfiles "github.com/swaggo/files"
	ginSwagger "github.com/swaggo/gin-swagger"
	"miomp-terminal-suite/backend/global"
	"miomp-terminal-suite/backend/i18n"
	routerALl "miomp-terminal-suite/backend/router"
	"miomp-terminal-suite/backend/router/middleware"
	"miomp-terminal-suite/docs"
)

var (
	Router *gin.Engine
)

func InitRouters() *gin.Engine {
	// 设置 Gin 模式为 release
	if "prod" == global.CONF.Mode {
		gin.SetMode(gin.ReleaseMode)
	}

	Router = gin.New()
	Router.Use(middleware.GinLogger()).Use(middleware.GinRecovery(true))

	//Router.NoRoute(func(c *gin.Context) {
	//	c.Writer.WriteHeader(http.StatusOK)
	//	_, _ = c.Writer.Write(web.IndexByte)
	//	c.Writer.Header().Add("Accept", "text/html")
	//	c.Writer.Flush()
	//})

	Router.Use(i18n.UseI18n())

	PrivateGroup := Router.Group("/api/v1")
	//PrivateGroup.Use(middleware.WhiteAllow())
	//PrivateGroup.Use(middleware.BindDomain())
	//PrivateGroup.Use(middleware.GlobalLoading())
	for _, router := range routerALl.Groups() {
		router.InitRouter(PrivateGroup)
	}
	docs.SwaggerInfo.BasePath = "/api/v1"
	Router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerfiles.Handler))

	return Router
}
